﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework.Utils;

namespace CNVP.JShop.Web.Controls
{
    public partial class AjaxProDetailNum : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int ProID = 0;
            int ProDetailID = 0;
            int CompareValue = 0;
            if (!string.IsNullOrEmpty(Request.QueryString["ProID"]) && Public.IsNumber(Request.QueryString["ProID"]))
            {
                ProID = Convert.ToInt32(Request.QueryString["ProID"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["ProDetailID"]) && Public.IsNumber(Request.QueryString["ProDetailID"]))
            {
                ProDetailID = Convert.ToInt32(Request.QueryString["ProDetailID"]);
            }
            if (!string.IsNullOrEmpty(Request.QueryString["CompareValue"]) && Public.IsNumber(Request.QueryString["CompareValue"]))
            {
                CompareValue = Convert.ToInt32(Request.QueryString["CompareValue"]);
            }
            string OperType = Request.QueryString["OperType"];
            BLL.BLLShoppingCar cart = new BLL.BLLShoppingCar();
            switch (OperType)
            {
                case "Update":
                    if (ProDetailID != 0)
                    {
                        var model_ProductsDetail = new BLL.CNVP_ProductsDetail().GetSingle_CNVP_ProductsDetailById(ProDetailID);
                        if (model_ProductsDetail != null)
                        {
                            if (CompareValue > model_ProductsDetail.StockNum)
                            {
                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write(1);
                                cart.UpdateAmount(Convert.ToString(ProID), Convert.ToString(ProDetailID), Convert.ToString(CompareValue));//更新Cookie
                            }
                        }
                    }
                    else
                    {
                        var model_Products = new BLL.CNVP_Products().GetSingle_CNVP_ProductsById(ProID);
                        if (model_Products != null)
                        {
                            if (CompareValue > model_Products.StockTotalNum)
                            {
                                Response.Write(0);
                            }
                            else
                            {
                                Response.Write(1);
                                cart.UpdateAmount(Convert.ToString(ProID), Convert.ToString(ProDetailID), Convert.ToString(CompareValue));//更新Cookie
                            }
                        }
                    }
                    break;
                case "Delete":
                    cart.Delete(Convert.ToString(ProID), Convert.ToString(ProDetailID),Convert.ToString(CompareValue));//删除Cookie
                    break;
            }

        }
    }
}